home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / othergnu / gnuplot.zoo / demo / bivariat.demo < prev    next >
Text File  |  1992-03-02  |  3KB  |  113 lines

  1. #
  2. # This demo is very slow and requires unusually large stack size.
  3. # Do not attempt to run this demo under MSDOS.
  4. #
  5.  
  6. # the function integral_f(x) approximates the integral of f(x) from 0 to x.
  7. # integral2_f(x,y) approximates the integral from x to y.
  8. # define f(x) to be any single variable function
  9. #
  10. # the integral is calculated as the sum of f(x_n)*delta 
  11. #   do this x/delta times (from x down to 0)
  12. #
  13. f(x) = exp(-x**2)
  14. delta = 0.025
  15. #
  16. # integral_f(x) takes one variable, the upper limit.  0 is the lower limit.
  17. # calculate the integral of function f(t) from 0 to x
  18. integral_f(x) = (x>0)?integral1a(x):-integral1b(x)
  19. integral1a(x) = (x<=0)?0:(integral1a(x-delta)+delta*f(x))
  20. integral1b(x) = (x>=0)?0:(integral1b(x+delta)+delta*f(x))
  21. #
  22. # integral2_f(x,y) takes two variables; x is the lower limit, and y the upper.
  23. # claculate the integral of function f(t) from x to y
  24. integral2_f(x,y) = (x<y)?integral2(x,y):-integral2(y,x)
  25. integral2(x,y) = (x>y)?0:(integral2(x+delta,y)+delta*f(x))
  26.  
  27. set title "approximate the integral of functions"
  28. set samples 50
  29.  
  30. plot [-5:5] f(x) title "f(x)=exp(-x**2)", 2/sqrt(pi)*integral_f(x) title "erf(x)=2/sqrt(pi)*integral_f(x)"
  31.  
  32. pause -1 "Hit return to continue"
  33.  
  34. f(x)=sin(x)
  35.  
  36. plot [-5:5] f(x) title "f(x)=sin(x)", integral_f(x)
  37.  
  38. pause -1 "Hit return to continue"
  39.  
  40. set title "approximate the integral of functions (upper and lower limits)"
  41.  
  42. f(x)=(x-2)**2-20
  43.  
  44. plot [-10:10] f(x) title "f(x)=(x-2)**2-20", integral2_f(-5,x)
  45.  
  46. pause -1 "Hit return to continue"
  47.  
  48. f(x)=sin(x-1)-.75*sin(2*x-1)+(x**2)/8-5
  49.  
  50. plot  [-10:10] f(x) title "f(x)=sin(x-1)-0.75*sin(2*x-1)+(x**2)/8-5", integral2_f(x,1)
  51.  
  52. pause -1 "Hit return to continue"
  53.  
  54. #
  55. # This definition computes the ackermann. Do not attempt to compute its
  56. # values for non integral values. In addition, do not attempt to compute
  57. # its beyond m = 3, unless you want to wait really long time.
  58.  
  59. ack(m,n) = (m == 0) ? n + 1 : (n == 0) ? ack(m-1,1) : ack(m-1,ack(m,n-1))
  60.  
  61. set xrange [0:3]
  62. set yrange [0:3]
  63.  
  64. set isosamples 4
  65. set samples 4
  66.  
  67. set title "Plot of the ackermann function"
  68.  
  69. splot ack(x, y)
  70.  
  71. pause -1 "Hit return to continue"
  72.  
  73. set xrange [-5:5]
  74. set yrange [-10:10]
  75. set isosamples 10
  76. set samples 100
  77. set key 4,-3
  78. set title "Min(x,y) and Max(x,y)"
  79.  
  80. #
  81. min(x,y) = (x < y) ? x : y
  82. max(x,y) = (x > y) ? x : y
  83.  
  84. plot sin(x), x**2, x**3, max(sin(x), min(x**2, x**3))+0.5
  85.  
  86. pause -1 "Hit return to continue"
  87.  
  88. #
  89. # gcd(x,y) finds the greatest common divisor of x and y,
  90. #          using Euclid's algorithm
  91. # as this is defined only for integers, first round to the nearest integer
  92. gcd(x,y) = gcd1(rnd(max(x,y)),rnd(min(x,y)))
  93. gcd1(x,y) = (y == 0) ? x : gcd1(y, x - x/y * y)
  94. rnd(x) = int(x+0.5)
  95.  
  96. set samples 59
  97. set xrange [1:59]
  98. set auto
  99. set key
  100.  
  101. set title "Greatest Common Divisor (for integers only)"
  102.  
  103. plot gcd(x, 60)
  104. pause -1 "Hit return to continue"
  105.  
  106. set xrange [-10:10]
  107. set yrange [-10:10]
  108. set auto
  109. set isosamples 10
  110. set samples 100
  111. set title ""
  112.  
  113.